#include "base/log.h"

#include "MyRpc/rpc.h"
namespace myrpc::base
{

  Rpc::Rpc()
      : rpc_vec_()
  {
    rpc_vec_.resize(rpc_type_size_ + 1);
  };
  unsigned int Rpc::Call_fun(net_tools::net::Connect *connect, char *buf)
  {
    uint32_t type = Analyze_uint(buf);
    buf += head_size_;
    uint32_t len = Analyze_uint(buf);
    buf += len_size_;
    bool ret = *buf;
    buf += 1;
    unsigned int ret_len = head_size_ + len_size_ + 1 + len;
    if (Rpc_type_is_available(type)) [[likely]]
    {
      if (rpc_vec_[type]) [[unlikely]]
      {
        if (ret)
        {
          rpc_vec_[type].Final_call_ret(buf, connect);
        }
        else
        {
          rpc_vec_[type].Final_call(buf);
        }
      }
    }
    return ret_len;
  };
  uint32_t Rpc::Analyze_uint(char *buf) const
  {
    return *reinterpret_cast<uint32_t *>(buf);
  };

} // namespace myrpc::base